package com.gjzt.business.media.controller;

import com.google.zxing.WriterException;
import net.sf.json.JSONObject;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.eastdigit.servlet.RequestAttribute;
import com.eastdigit.servlet.Response;
import com.eastdigit.servlet.ReqBean;
import com.gjzt.business.media.service.MediaResourceMarksService;
import com.gjzt.business.media.service.MediaStopService;
import com.gjzt.business.media.service.MediaTypeService;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Controller
@RequestMapping(value = "/media/stop")
public class MediaStopController {

    @Autowired
    private MediaStopService mediaStopService;

    @Autowired
    private MediaTypeService mediaTypeService;

    @Autowired
    private MediaResourceMarksService mediaResourceMarksService;

    /**
     * 查询站点
     * 
     * @param reqBean
     * @return
     */
    @RequestMapping(value = "/query")
    @ResponseBody
    public JSONObject queryMediaStop(final @RequestAttribute(ReqBean.NAME) ReqBean reqBean) {
        return Response.response(mediaStopService.findMediaStop(reqBean));
    }

    /**
     * 查询站点媒体类型
     * 
     * @param reqBean
     * @return
     */
    @RequestMapping(value = "/mediatypes")
    @ResponseBody
    public JSONObject queryBusMedias(final @RequestAttribute(ReqBean.NAME) ReqBean reqBean) {
        return Response.response(mediaTypeService.queryStopMediaType());
    }

    @RequestMapping(value = "/equipment")
    @ResponseBody
    public JSONObject equipment(final @RequestAttribute(ReqBean.NAME) ReqBean reqBean) {
        return Response.response(mediaStopService.equipment(reqBean));
    }

    @RequestMapping(value = "/equipmentAdd")
    @ResponseBody
    public JSONObject equipmentAdd(final @RequestAttribute(ReqBean.NAME) ReqBean reqBean) {
        mediaStopService.equipmentAdd(reqBean);
        return Response.responseSuccess();
    }

    @RequestMapping(value = "/selectStopEquipments")
    @ResponseBody
    public JSONObject selectStopEquipments(final @RequestAttribute(ReqBean.NAME) ReqBean reqBean) {
        return Response.response(mediaStopService.selectStopEquipments(reqBean));
    }

    @RequestMapping(value = "/equipmentUpdate")
    @ResponseBody
    public JSONObject equipmentUpdate(final @RequestAttribute(ReqBean.NAME) ReqBean reqBean) {
        mediaStopService.equipmentUpdate(reqBean);
        return Response.responseSuccess();
    }

    @RequestMapping(value = "/equipmentDelete")
    @ResponseBody
    public JSONObject equipmentDelete(final @RequestAttribute(ReqBean.NAME) ReqBean reqBean) {
        mediaStopService.equipmentDelete(reqBean);
        return Response.responseSuccess();
    }

    /**
     * 查询站点环境标签
     * 
     * @param reqBean
     * @return
     */
    @RequestMapping(value = "/{stopId}/marks")
    @ResponseBody
    public JSONObject queryMarksOfBus(@PathVariable String stopId) {
        return Response.response(mediaResourceMarksService.queryMarksOfStop(stopId));
    }

    @RequestMapping(value = "/{stopId}/info")
    @ResponseBody
    public JSONObject getBusInfo(@PathVariable String stopId) {
        return Response.response(mediaStopService.getMediaStopInfo(stopId));
    }

    @RequestMapping(value = "/{stopId}/infoWithRes")
    @ResponseBody
    public JSONObject getBusInfoWithRes(@PathVariable String stopId) {
        return Response.response(mediaStopService.getMediaStopInfoWithRes(stopId));
    }

    /**
     * 保存
     * 
     * @param reqBean
     * @return
     */
    @RequestMapping(value = "/save")
    @ResponseBody
    public JSONObject saveMediaStop(final @RequestAttribute(ReqBean.NAME) ReqBean reqBean) {
        mediaStopService.saveMediaStop(reqBean);
        return Response.responseSuccess();
    }

    /**
     * 保存
     * 
     * @param reqBean
     * @return
     */
    @RequestMapping(value = "/dealQrCode")
    @ResponseBody
    public JSONObject dealQrCode(final @RequestAttribute(ReqBean.NAME) ReqBean reqBean, HttpServletRequest request,
            HttpServletResponse response) throws IOException, WriterException {
        mediaStopService.dealQrCode(reqBean, request, response);
        return Response.responseSuccess();
    }

}